//
//  AppDelegate.m
//  B段项目
//
//  Created by 徐茂怀 on 15/11/2.
//  Copyright © 2015年 徐茂怀. All rights reserved.
//

#import "AppDelegate.h"
#import "FindMeishiViewController.h"
#import "MeishiListViewController.h"
#import "MeishiZhuantiViewController.h"
#import "ShipingViewController.h"
#import "WoViewController.h"
#import "FitHeader.h"
#define ScreenSize [UIScreen mainScreen].bounds.size.width
@interface AppDelegate ()
@property(nonatomic , retain)UIScrollView *scrollView;
@property(nonatomic, strong)UIImageView *imageView4;
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
    // Override point for customization after application launch.
    _window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    _window.backgroundColor = [UIColor whiteColor];
    [_window makeKeyAndVisible];
    //美食列表
    MeishiListViewController *mlvc = [[MeishiListViewController alloc]init];
    UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:mlvc];
    mlvc.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"美食列表" image:[UIImage imageNamed:@"iconfont-04meishi.png"] tag:1000];
    //发现美食
    FindMeishiViewController *findvc = [[FindMeishiViewController alloc]init];
    UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:findvc];
    findvc.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"发现美食" image:[UIImage imageNamed:@"iconfont-shaixuantubiaogaozhuanqu08.png"] tag:1001];
    //美食专题
    MeishiZhuantiViewController *zhuantivc = [[MeishiZhuantiViewController alloc]init];
    UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:zhuantivc];
    zhuantivc.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"美食专题" image:[UIImage imageNamed:@"iconfont-meishi.png"] tag:1002];
    //视频菜谱
    ShipingViewController *shipingvc = [[ShipingViewController alloc]init];
    UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:shipingvc];
    shipingvc.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"视频菜谱" image:[UIImage imageNamed:@"iconfont-hotfood.png"] tag:1003];
    //我
    WoViewController *wovc = [[WoViewController alloc]init];
    UINavigationController *nav5 = [[UINavigationController alloc]initWithRootViewController:wovc];
    wovc.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"我" image:[UIImage imageNamed:@"iconfont-wo (1).png"] tag:1004];
    
    UITabBarController *tabbarController = [[UITabBarController alloc]init];
    tabbarController.tabBar.translucent = NO;
    tabbarController.tabBar.tintColor = [UIColor colorWithRed:0.12 green:0.63 blue:0.59 alpha:1];
    tabbarController.viewControllers = @[nav1,nav2,nav3,nav4,nav5];
    _window.rootViewController = tabbarController;
    [self welcomeView];
    return YES;
}


-(void)welcomeView
{
    if (![[NSUserDefaults standardUserDefaults]boolForKey:@"firstLaunch"])
    {
        [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"firstLaunch"];
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
        [_scrollView setContentSize:CGSizeMake([UIScreen mainScreen].bounds.size.width * 4, 0)];
        [_scrollView setPagingEnabled:YES];
        [_scrollView setBounces:NO];
        
        
        UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
        [imageView1 setImage:[UIImage imageNamed:@"xyindao1.png"]];
        [_scrollView addSubview:imageView1];
        
        UIImageView *imageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenSize, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
        [imageView2 setImage:[UIImage imageNamed:@"xyindao2.png"]];
        [_scrollView addSubview:imageView2];

        UIImageView *imageView3 = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenSize * 2, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
        [imageView3 setImage:[UIImage imageNamed:@"xyindao3.png"]];
        [_scrollView addSubview:imageView3];
        
        _imageView4 = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenSize * 3, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
        _imageView4.userInteractionEnabled = YES;
        [_imageView4 setImage:[UIImage imageNamed:@"xyindao4.png"]];
        [_scrollView addSubview:_imageView4];
        
        UIButton *button = [UIButton buttonWithType: UIButtonTypeSystem];
        button.frame = CGRectMake(100 * FitWidth, 600 * FitHeight, 175 * FitWidth, 50 * FitHeight);
        [button setTitle:@"立即体验" forState:UIControlStateNormal];
        button.layer.cornerRadius = 10;
        button.layer.borderWidth = 1;
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        button.layer.borderColor = [UIColor whiteColor].CGColor;
        [button addTarget:self action:@selector(removeAction) forControlEvents:UIControlEventTouchUpInside];
        [_imageView4 addSubview:button];
        
        [_window addSubview:_scrollView];
    }
}

-(void)removeAction
{
    [UIView animateWithDuration:1 animations:^{  
        _imageView4.transform = CGAffineTransformMakeRotation(M_PI);
        _imageView4.alpha = 0.3;
    } completion:^(BOOL finished) {
        
        [_scrollView removeFromSuperview];
    }];
}

- (void)applicationWillResignActive:(UIApplication *)application
{
   
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
